package com.yc.cloud.mapper;

import com.yc.cloud.entity.UmsMenu;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 后台菜单表 Mapper 接口
 * </p>
 *
 * @author JackGu
 * @since 2022-09-11
 */
@Mapper
public interface UmsMenuMapper extends BaseMapper<UmsMenu> {
    @Select("SELECT\n" +
            "            m.id id,\n" +
            "            m.parent_id parentId,\n" +
            "            m.create_time createTime,\n" +
            "            m.title title,\n" +
            "            m.level level,\n" +
            "            m.sort sort,\n" +
            "            m.name name,\n" +
            "            m.icon icon,\n" +
            "            m.hidden hidden\n" +
            "        FROM\n" +
            "            ums_admin_role_relation arr\n" +
            "                LEFT JOIN ums_role r ON arr.role_id = r.id\n" +
            "                LEFT JOIN ums_role_menu_relation rmr ON r.id = rmr.role_id\n" +
            "                LEFT JOIN ums_menu m ON rmr.menu_id = m.id\n" +
            "        WHERE\n" +
            "            arr.admin_id = #{adminId}\n" +
            "          AND m.id IS NOT NULL\n" +
            "        GROUP BY\n" +
            "            m.id")
    List<UmsMenu> getMenuList(Long adminId);


    @Select("SELECT\n" +
            "            m.id id,\n" +
            "            m.parent_id parentId,\n" +
            "            m.create_time createTime,\n" +
            "            m.title title,\n" +
            "            m.level level,\n" +
            "            m.sort sort,\n" +
            "            m.name name,\n" +
            "            m.icon icon,\n" +
            "            m.hidden hidden\n" +
            "        FROM\n" +
            "             ums_role_menu_relation rmr\n" +
            "                LEFT JOIN ums_menu m ON rmr.menu_id = m.id\n" +
            "        WHERE\n" +
            "            rmr.role_id = #{roleId}\n" +
            "          AND m.id IS NOT NULL\n" +
            "        GROUP BY\n" +
            "            m.id")
    List<UmsMenu> queryByRoleId(@Param("roleId") Long roleId);
}
